<?php
/**
 * Created by PhpStorm.
 * User: qingyun
 * Date: 17/5/3
 * Time: 下午9:46
 */
namespace Admin\Controller;
use Common\Controller\AdminBaseController;
class PasswordController extends AdminBaseController{
    public function index(){
        $list = M('admin')->field('id,username,password')->where(['id'=>session('user.id')])->find();
        $this->assign('list',$list);
        $this->display();
    }
    public function save(){
        $id = I('post.id/d',0);
        if(!$id){
            $this->ajaxReturn(['status'=>0,'mag'=>'非法操作']);
        }
        $new = M('admin');
        $content = $new->field('id,username,password')->where(['id'=>$id])->find();
        $password = _md5(I('post.password/s',''));
        if($password != $content['password']){
            $this->ajaxReturn(['status'=>0,'msg'=>'原始密码错误']);
        }
        $newpassword = _md5(I('post.newpassword/s',''));
        $renewpass = _md5(I('post.renewpass/s',''));
        if($newpassword != $renewpass){
            $this->ajaxReturn(['status'=>0,'msg'=>'两次密码不一致,请重新输入']);
        }
        $updates = $new->where(['id'=>$id])->setField(['password'=>$newpassword]);
        if(!$updates){
            $this->ajaxReturn(['status'=>0,'msg'=>'修改失败']);
        }
        $this->ajaxReturn(['status'=>1,'msg'=>'修改成功']);
        

    }
}